package com.hkts.naturalgas.utils;

import com.alibaba.nacos.client.naming.utils.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

public class resultMapUtils {

    public static Map<String, List<Object>> resultData(List<Map<String,Object>> list){
        Map<String, List<Object>> maps = new HashMap<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> stringObjectMap = list.get(i);
            for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()){

                if (!maps.containsKey(entry.getKey()) && !entry.getKey().equals("time")){
                    List<Object> valuess = new ArrayList<>();
                    valuess.add(entry.getValue());
                    maps.put(entry.getKey(),valuess);
                }else if (!entry.getKey().equals("time")){
                    List<Object> lists = maps.get(entry.getKey());
                    lists.add(entry.getValue());
                    maps.put(entry.getKey(),lists);
                }

            }

        }
        return maps;
    }
    public static List<Object> getList(List<Map<String,Object>> list){
        List<Object> valuess = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> stringObjectMap = list.get(i);
            for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()){
                if (entry.getKey().equals("time")){
                    valuess.add(entry.getValue());
                }
            }
        }
        return valuess;
    }
    public static List<Object> getListName(List<Map<String,Object>> list){
        List<Object> valuess = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> stringObjectMap = list.get(i);
            for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()){
                if (!entry.getKey().equals("time")){
                    valuess.add(entry.getKey());
                }
            }
            break;
        }
        return valuess;
    }

    public static List<Object> addH(List<Object> list){
        list.add(14,"");
        return list;
    }

    public static List<Object> swasp(List<Object> list, int pos1, int pos2) {
        //判断list是否为空
        if (CollectionUtils.isEmpty(list)) {
            return list;
        }
        //创建一个临时变量存储数据
        Object e = list.get(pos1);
        //调换
        list.set(pos1, list.get(pos2));
        list.set(pos2, e);
        return list;
    }
}
